
import { request } from '../request'
import type { CartVO, CartAddDTO } from '@/types'

// 获取购物车
export const getCart = (): Promise<CartVO> => {
    return request.get('/cart-service/api/cart')
}

// 加入购物车
export const addToCart = (data: CartAddDTO): Promise<void> => {
    return request.post('/cart-service/api/cart', data)
}

// 更新购物车商品数量
export const updateCartItem = (productId: number, quantity: number): Promise<void> => {
    return request.put(`/cart-service/api/cart/${productId}`, null, {
        params: { quantity }
    })
}

// 从购物车移除商品
export const removeCartItem = (productId: number): Promise<void> => {
    return request.delete(`/cart-service/api/cart/${productId}`)
}

// 清空购物车
export const clearCartItems = (productIds: number[]): Promise<void> => {
    return request.post('/cart-service/api/cart/inner/clear-items', productIds)
}
